<?php

namespace backend\modules\system\controllers;

use Yii;
use yii\helpers\Url;
use common\models\SysUser;

class PublicController extends \backend\controllers\BaseController
{
    /**
     * 修改密码
     */
    public function actionPassword($type = '')
    {
        /*if ($this->userInfo->user_type == 4) {
            return $this->redirect(['/system/site/index']);
        }*/
//        $this->layout = '/agent';
        $model = new SysUser();
        $model->setScenario('editPass');

        if ($model->load(Yii::$app->request->post())) {
            if ($model->editPassword()) {
//                if ($type == 'boss') {
                Yii::$app->session->setFlash('tips_msg', '修改成功');
                exit("<script>parent.layer.close(parent.layer.getFrameIndex(window.name));</script>");
//                return $this->redirect(Yii::$app->request->referrer);
//                exit( "<script>top.location.href='" . Url::to(['/business/shopmanage/list']) . "'</script>" );
//                }
//                Yii::$app->getSession()->setFlash('success', '修改成功！');
//                return $this->redirect(['password']);
            } else {
                Yii::$app->session->setFlash('passError', '1');
                return $this->redirect(['password', 'type' => 'boss']);
            }
        }
        if ($errors = $model->getErrors()) {
            $this->error(\common\extended\system\Util::handelErrors($errors));
        }
        if ($type == 'boss') {
            $this->layout = '/alert';
            /*return $this->render('passwordBoss', [
                'model' => $model
            ]);*/
        }
        return $this->render('password', [
            'model' => $model
        ]);
    }
}